package lesson.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lesson.entity.Nucleic;
import lesson.service.NucleicService;
import lesson.vo.DataView;
import lesson.vo.NucleicVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * @Description:
 * @Author: Wanzhen
 * @Date: 2022/6/14-11:21
 */
@Controller
@RequestMapping("/nucleic")
public class NucleicController {

    @Autowired
    private NucleicService nucleicService;

    @RequestMapping("/toNucleic")
    public String toNucleic(){
        return "nucleic/nucleic";
    }

    @RequestMapping("/loadAllNucleic")
    @ResponseBody
    public DataView loadAllNucleic(NucleicVo nucleicVo){
        IPage<Nucleic> page = new Page<>(nucleicVo.getPage(), nucleicVo.getLimit());
        QueryWrapper<Nucleic> queryWrapper = new QueryWrapper<>();
        nucleicService.page(page, queryWrapper);
        return new DataView(page.getTotal(), page.getRecords());
    }

    @RequestMapping("/addNucleic")
    @ResponseBody
    public DataView addNucleic(Nucleic nucleic){
        nucleicService.save(nucleic);
        DataView dataView = new DataView();
        dataView.setCode(200);
        dataView.setMsg("添加核酸登记成功");
        return dataView;
    }

    @RequestMapping("/updateNucleic")
    @ResponseBody
    public DataView updateNucleic(Nucleic nucleic){
        nucleicService.updateById(nucleic);
        DataView dataView = new DataView();
        dataView.setCode(200);
        dataView.setMsg("修改核酸登记成功");
        return dataView;
    }

    @RequestMapping("/deleteNucleic")
    @ResponseBody
    public DataView deleteNucleic(Integer id){
        nucleicService.removeById(id);
        DataView dataView = new DataView();
        dataView.setCode(200);
        dataView.setMsg("删除核酸登记成功");
        return dataView;
    }

}
